﻿<link href="@Url.Content("~/content/activitie_detail.css")" rel="stylesheet" type="text/css"/>
<link href="@Url.Content("~/content/table_btn.css")" rel="stylesheet" type="text/css"/>

<!--[if !IE]> -->
    <link rel="stylesheet" href="@Url.Content("~/plugin/accordion/demo.css")">
    <script>document.documentElement.className = "js";</script>
    <script src="@Url.Content("~/plugin/accordion/json2.js")"></script>
    <script src="@Url.Content("~/plugin/accordion/jquery.collapse.js")"></script>
    <script src="@Url.Content("~/plugin/accordion/jquery.collapse_storage.js")"></script>
    <script src="@Url.Content("~/plugin/accordion/jquery.collapse_cookie_storage.js")"></script>
<!-- <![endif]-->

<!--[if gte IE 8]>
    <link rel="stylesheet" href="@Url.Content("~/plugin/accordion/demo.css")">
    <script>document.documentElement.className = "js";</script>
    <script src="@Url.Content("~/plugin/accordion/json2.js")"></script>
    <script src="@Url.Content("~/plugin/accordion/jquery.collapse.js")"></script>
    <script src="@Url.Content("~/plugin/accordion/jquery.collapse_storage.js")"></script>
    <script src="@Url.Content("~/plugin/accordion/jquery.collapse_cookie_storage.js")"></script>
<![endif]-->

<!--[if lt IE 8]>
    <link href="@Url.Content("~/content/activitie_create.css")" rel="stylesheet" type="text/css"/>
<![endif]-->

<noscript>
    <link href="@Url.Content("~/content/activitie_create.css")" rel="stylesheet" type="text/css"/>
    <link href="@Url.Content("~/content/activitie_noscript.css")" rel="stylesheet" type="text/css"/>
</noscript>

@model PessModel.Archive

@{
    ViewBag.Title = "Proposal Details";
}
 
<h2>Proposal Details</h2>
@*<div>@Html.ActionLink("编辑申报表", "Edit", "Archive", new {id=Model.ID },null)</div>*@
    <div>        
    @*@if(Roles.IsUserInRole("Admin"))
            {
                @Html.ActionLink("Re-score", "EditScores2", "Score", new { archiveID = Model.ID  }, null) 
            }*@
    </div>
@*<div id="operate">
    @if ((bool)ViewBag.IsArchiveModificationAllowed)
    {
        if (Roles.IsUserInRole("Admin"))
        {
            @Html.ActionLink("Edit", "Edit", "Archive", new { id = Model.ID }, null)             
        }
        else if( Roles.IsUserInRole("Author"))
        {
            @Html.ActionLink("Edit", "EditProposal", new { id = Model.ID })
        }
    }*@
    @*&#8195; @Html.ActionLink("Review Feedback", "Feedback", "Archive", new { serialNumber = Model.SerialNumber }, null)*@ 
    @*&#8195; @Html.ActionLink("历史档案", "PreviousArchives", "Archive", new { archiveID = Model.ID }, null)*@
    @*&#8195;@Html.ActionLink("Back", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID }, null)*@
    

@*</div>*@
<div id="custom-show-hide-example" >

<h3 class="open">Proposal</h3>
<div>
@Html.Partial("_ArchiveDetailsFull", Model)
</div>

   @if(Model.Attachments.Count>0)
      { 
    <h3 class="open"> Paper</h3>
    <div>
        <div id="showFile" class="displayValue">
            @{
                var grid = new WebGrid(Model.Attachments, defaultSort: "Title");
            }
            @grid.GetHtml(columns: from c in grid.Columns(
                 grid.Column("Title", header: " File Name "), //format: @<text>@Html.ActionLink((string)item.Title, "Download", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>),
                 grid.Column("FileSize", header: " Size（KB） "),
                 grid.Column("TimeStamp", header: " Date Modified "),
                 grid.Column("Review", header: "", format: @<text>@Html.ActionLink("Download", "Download", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>),
                 grid.Column("Operation", header: "Operation", format: @<text>@Html.ActionLink("Delete", "DeleteAttachment", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>)
             )
                               where !c.ColumnName.Contains("Operation") || (Roles.IsUserInRole("Admin") || Roles.IsUserInRole("CountyAdmin"))
                               select c
                          )
        </div>
        <br />
    </div>
      }

<!--Review Proposal Begin-->
<!--Reviewer-->
@if (Roles.IsUserInRole(Membership.GetUser().UserName, "ExpertJudge") && Model.Status >= 3)
{
    <h3 class="open">Review Proposal</h3>
    <div>

        @if (Model.Status == 3)//Review
        {
            <fieldset class="edit">
                <legend></legend>
                @using (Html.BeginForm("SaveReview", "Score", FormMethod.Post, new { id = "formReview", name = "formReview" }))
{
    int x = 0;
    foreach (var rule in Model.Subject.Rules)
    {
        var ascores = Model.Scores.Where(s => s.RuleID == rule.ID && s.ExpertJudgeSerialNumber == Membership.GetUser().UserName);
        int svalue = 0;
        if (ascores.Count() == 1)
        {
            svalue = Convert.ToInt32(ascores.FirstOrDefault().Value);
        }

        <div class="editor-label editor-label-rules">@rule.Name</div>
    <div class="editor-field editor-field-rules">
        @for (int i = 1; i <= rule.Value; i++)
        {
            //<input type="radio" name="@rule.ID" value="@i" style="margin-left:10px" /> @i
            if (svalue == i)
            {
                <input type="radio" name="scores[@x].ScoreValue" value="@i" style="margin-left:10px" checked="checked" /> @i
            }
            else
            {
                <input type="radio" name="scores[@x].ScoreValue" value="@i" style="margin-left:10px" required /> @i
            }
            @Html.Hidden("scores[" + x + "].RuleID", rule.ID)
        }
        <span class="field-validation-valid" data-valmsg-for="scores[@x].ScoreValue" data-valmsg-replace="true"></span>
    </div>
        x++;
    }

    var pessEC = Model.ExpertComments.Where(ecc => ecc.ArchiveID == Model.ID && ecc.ExpertSerialNumber == Membership.GetUser().UserName).FirstOrDefault();
    if (pessEC == null) //new review
    {
                        <div class="editor-label editor-label-rules">Recommendation</div>
                        <div class="editor-field editor-field-rules">
                            <input type="radio" value="1" name="accepted" required /> Accept
                            <input type="radio" value="0" name="accepted" /> Reject
                            <span class="field-validation-valid" data-valmsg-for="accepted" data-valmsg-replace="true"></span>
                        </div>
                        <div class="editor-label editor-label-rules" style="height:90px">Comments to the author</div>
                        <div class="editor-field editor-field-rules">
                            <textarea id="Comment" name="Comment" style="width:600px;" required></textarea><br />
                            <span class="field-validation-valid" data-valmsg-for="Comment" data-valmsg-replace="true"></span>
                        </div>
                        <div class="editor-label editor-label-rules" style="height:90px">Comments to the review board chair</div>
                        <div class="editor-field editor-field-rules">
                            <textarea id="CommentsForChair" name="CommentsForChair" style="width:600px;" required></textarea><br />
                            <span class="field-validation-valid" data-valmsg-for="CommentsForChair" data-valmsg-replace="true"></span>
                        </div>
                    }
                    else //existing review
                    {
                        <div class="editor-label editor-label-rules">Recommendation: </div>
                        if (pessEC.AcceptanceStatus == 0)
                        {
                            <div class="editor-field editor-field-rules">
                                <input type="radio" value="1" name="accepted" required /> Accept
                                <input type="radio" value="0" name="accepted" checked="checked" /> Reject
                                <span class="field-validation-valid" data-valmsg-for="accepted" data-valmsg-replace="true"></span>
                            </div>
                        }
                        else
                        {
                            <div class="editor-field editor-field-rules">
                                <input type="radio" value="1" name="accepted" checked="checked" required /> Accept
                                <input type="radio" value="0" name="accepted" /> Reject
                                <span class="field-validation-valid" data-valmsg-for="accepted" data-valmsg-replace="true"></span>
                            </div>
                        }
                        <div class="editor-label editor-label-rules" style="height:90px">Comments to the author</div>
                        <div class="editor-field editor-field-rules">
                            <textarea id="Comment" name="Comment" style="width:600px;" required>@pessEC.Comment</textarea><br />
                            <span class="field-validation-valid" data-valmsg-for="Comment" data-valmsg-replace="true"></span>
                        </div>
                        <div class="editor-label editor-label-rules" style="height:90px">Comments to the review board chair</div>
                        <div class="editor-field  editor-field-rules">
                            <textarea id="CommentsForChair" name="CommentsForChair" style="width:600px;" required>@pessEC.CommentsForChair</textarea><br />
                            <span class="field-validation-valid" data-valmsg-for="CommentsForChair" data-valmsg-replace="true"></span>
                        </div>
                    }

                    <input type="hidden" name="archiveid" value="@Model.ID" />
                    <input type="hidden" name="round" value="@ViewBag.Round" />
                    <div class="editor-btn editor-btn-rules">
                        @if (Model.Status == 3)
                        {
                            <input type="submit" id="btnsave" value="Save" />
                        }
                        @if (Model.Status == 3)
                        {
                            @Html.ActionLink("Cancel", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID, round = ViewBag.Round }, null);
                        }

                    </div>
}
            </fieldset>

        }
        else if (Model.Status > 3)//Review (View Only)
        {
             <fieldset class="show">
                <legend></legend>
                    @{decimal totalscore = 0;}
                    @foreach (var rule in Model.Subject.Rules)
                    {
                        var ascores = Model.Scores.Where(s => s.RuleID == rule.ID && s.ExpertJudgeSerialNumber == Membership.GetUser().UserName);
                        int svalue = 0;
                        if (ascores.Count() == 1)
                        {
                            svalue = Convert.ToInt32(ascores.FirstOrDefault().Value);
                            totalscore+=svalue;
                        }
                        
                        <div class="display-label-rules">@rule.Name</div>
                        <div class="display-field-rules">
                            @svalue
                        </div>
                    }
                    
                 <div class="display-label-rules">Total</div>
                 <div class="display-field-rules">
                     @((totalscore/60).ToString("P1"))
                 </div>


                    @{var pessEC = Model.ExpertComments.Where(ecc => ecc.ArchiveID == Model.ID && ecc.ExpertSerialNumber == Membership.GetUser().UserName).FirstOrDefault(); }
                    @if (pessEC == null)
                    {

                    }
                    else
                    {
                        <div class="display-label-rules">Comment to the author:</div>
                        <div class="display-field-rules">
                           @pessEC.Comment
                        </div>
                        <div class="display-label-rules">Comment to the review board chair:</div>
                        <div class="display-field-rules">
                           @pessEC.CommentsForChair
                        </div>
                        <div class="display-label-rules">Recommendation</div>
                            <div class="display-field-rules">
                                @((PessModel.AcceptanceStatus)pessEC.AcceptanceStatus)
                            </div>
                    }

                 

            </fieldset>
    <div id="operate_bottom">
        @Html.ActionLink("Back", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID,round=ViewBag.Round }, null)
    </div>
        }
    </div>
}
    <!--Review Proposal End-->



<!--All of below-->
@if (User.IsInRole("Admin") || User.IsInRole("Chair") || User.IsInRole("Editor"))
{
    <h3 class="open"> Proposal Review Results</h3>
    <div>
    <fieldset class="show">
    <legend></legend>
    
    @if (Model.ExpertComments.Count > 0)//list all reviewers' results
    {
        int x = 1;
        foreach (var rf in Model.ExpertComments)
        {
            <div class="ReviewBox">
                <div class="ReviewHeader" style="margin-top:-15px;">Review #@x: @rf.ExpertJudge.RealName
                    @if (rf.AcceptanceStatus == 1)
                    {
                        <img src="@Url.Content("~/images/green20.png")" alt="Accepted" style="vertical-align:text-top;margin-left:30px;" title="Accepted" />;
                    }
                    else if (rf.AcceptanceStatus == 0)
                    {
                        <img src="@Url.Content("~/images/red20.png")" alt="Rejected" style="vertical-align:text-top;margin-left:30px;" title="Rejected" />;
                    }
                </div>
                <div class="ReviewBody" style="">
                    @foreach (var s in Model.Scores.Where(s => s.ExpertJudgeSerialNumber == rf.ExpertSerialNumber))
                    {
                        <div class="display-label-rules">
                             @s.Rule.Name
                        </div>
                        <div class="display-field-rules">
                            @s.Value
                        </div>
                    }
                    <div class="display-label-rules">
                        Total
                    </div>
                    <div class="display-field-rules">
                        @((Model.Scores.Where(s => s.ExpertJudgeSerialNumber == rf.ExpertSerialNumber).Sum(s => s.Value) / 60).Value.ToString("P1"))
                    </div>
                    <div class="display-label-rules" >
                        Comment to the author
                    </div>
                    <div class="display-field-rules">
                        @rf.Comment
                    </div>
                    <div class="display-label-rules">
                        Comment to the review board chair
                    </div>
                    <div class="display-field-rules">
                        @rf.CommentsForChair
                    </div>
                    <div class="display-label-rules" >
                        Recommendation
                    </div>
                    <div class="display-field-rules">
                        @((PessModel.AcceptanceStatus)rf.AcceptanceStatus)
                    </div>
                </div>
            </div>
                    x++;
        }
    }
    else
    {
        <p>There is no review record available for this proposal!</p>
    }

        @if (!User.IsInRole("Chair"))
        {
        
        <div class="ReviewBox">
            <div class="ReviewHeader" style="margin-top:-15px;">
               Chair's Feedbacl
            </div>
            <div class="ReviewBody" style="">
                <div class="display-label">
                    Submitted Format:
                </div>
                <div class="display-field">
                    @Html.Label(Model.County.Name)
                </div>

                <div class="display-label">
                    Suggested Format:
                </div>
                <div class="display-field">
                    @Html.Label(Model.County1.Name)
                </div>

                <div class="display-label">
                    Proposal Acceptance:
                </div>
                <div class="display-field">
                    <span>@Model.StatusName</span>
                </div>

                <div class="display-label">
                    Chair's Feedback:
                </div>
                <div class="display-field">
                    <span>@MvcHtmlString.Create(@Model.ChairProposalFeedBack)</span>
                </div>
            </div>
        </div>
        }
        
        </fieldset>


        @if (!User.IsInRole("Chair")) { 
        <div id="operate_bottom">
        @Html.ActionLink("Back", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID, round = ViewBag.Round }, null)
        </div>
        }
        </div>
}

@if (User.IsInRole("Chair"))
{
    <h3 class="open"> Chair Review</h3>
    <div>
       @if (Model.Status >2) { //under review
         
           <fieldset class="edit">
            <legend></legend>
            @using (Html.BeginForm("Accept", "Archive", FormMethod.Post, new { id = "formChairReview", name="formChairReview"}))
                {
            if(Model.Status==3)
            { 
            <div class="editor-label">
                Submitted Format:
            </div>
            <div class="editor-field">
                @Html.Label(Model.County.Name)
            </div>

            <div class="editor-label">
                Suggested Format:
            </div>
            <div class="editor-field">
                @Html.DropDownList("SuggestedCategory")
                <span class="field-validation-valid" data-valmsg-for="SuggestedCategory" data-valmsg-replace="true"></span>
            </div>
                
               <div class="editor-label">Proposal Acceptance: </div>
                        <div class="editor-field">
                            <input type="radio" value="4" name="accept" required /> Accept
                            <input type="radio" value="5" name="accept"  /> Reject
                            <span class="field-validation-valid" data-valmsg-for="accept" data-valmsg-replace="true"></span>
                </div>
                
                
            }
            else
            {
                <div class="editor-label">
                    Submitted Format:
                </div>
                <div class="editor-field">
                    @Html.Label(Model.County.Name)
                </div>

                <div class="editor-label">
                    Suggested Format:
                </div>
                <div class="editor-field">
                    @Html.Label(Model.County1.Name)
                </div>

                <div class="editor-label">
                    Proposal Acceptance:
                </div>
                <div class="editor-field">
                    <span>@Model.StatusName</span>
                </div>
                <input type="hidden" name="SuggestedCategory" value="@Model.County1.Code" />
                <input type="hidden" name="accept" value="@Model.Status" />
            }
                <div class="editor-label" style="height:90px">Feedback</div>
                        <div class="editor-field  editor-field-rules">
                            <textarea id="ChairProposalFeedback" name="ChairProposalFeedback" style="width:600px;" >@(!string.IsNullOrEmpty(@Model.ChairProposalFeedBack)?@Model.ChairProposalFeedBack.Replace("&lt;", "<").Replace("&gt;", ">").Replace("<br/>", "\n"):"")</textarea><br />
                        </div>
                
                <input type="hidden" name="id" value="@Model.ID" />
                <input type="hidden" name="round" value="@ViewBag.Round" />
                
                    <div class="editor-btn">
                        @*@if (Model.Status == 3)
                        {*@
                            <input type="submit" id="btnChairSave" value="Save" />
                        @*}
                        @if (Model.Status == 3)
                        {*@
                            @Html.ActionLink("Cancel", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID, round = ViewBag.Round }, null)
                        @*}*@
                       
                    </div>
            }
        </fieldset>
       }
       else
       {
           <fieldset class="show">
            <legend></legend>
            
            <div >
                Review is not started!
            </div>
              
        </fieldset>
           <div id="operate_bottom">
            @Html.ActionLink("Back", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID, round = ViewBag.Round }, null)
        </div>
       }       
    </div>
}
@*else if (User.IsInRole("Admin") || User.IsInRole("Editor"))
    {//readonly
        <fieldset class="show">
            <legend></legend>

            <div class="display-label">
                Submitted Format:
            </div>
            <div class="display-field">
                @Html.Label(Model.County.Name)
            </div>

            <div class="display-label">
                Suggested Format:
            </div>
            <div class="display-field">
                @Html.Label(Model.County1.Name)
            </div>

            <div class="display-label">
                Proposal Acceptance:
            </div>
            <div class="display-field">
                <span>@Model.StatusName</span>
            </div>

            <div class="display-label">
                Chair's Feedback:
            </div>
            <div class="display-field">
                <span>@MvcHtmlString.Create(@Model.ChairProposalFeedBack)</span>
            </div>
        </fieldset>

        <div id="operate_bottom">            
            @Html.ActionLink("Back", "Index", new { activityID = Model.Subject.ActivityID, archiveID = Model.ID }, null)
        </div>
    }*@

</div>

<div id="dialog-message" title="Message">
    <p>
        <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;">Message</span>
        <span id="msg_in_dialog"></span>
    </p>
</div>

 
@*<script language="javascript">
    for (i=0;i< document.getElementsByTagName("table").length;i++){
        document.getElementsByTagName("table")[i].className = "oddTable";
    }
</script>*@
@*<p>@Html.Action("EditScores","Score",new {archiveID=Model.ID})</p>*@

@*<script>
    $(document).ready(function(){
        $(".help h3").click(function(){ 
            $(this).next("p").slideToggle("fast").siblings("p:visible").slideUp("fast");  
        });
    });
</script>*@

<!--[if !IE]> -->
      <script>
          $(document).ready(function () {
              new jQueryCollapse($("#custom-show-hide-example"), {
                  open: function () {
                      this.slideDown(150);
                  },
                  close: function () {
                      this.slideUp(150);
                  }
              });

          });


      </script>
<!-- <![endif]-->

<!--[if gte IE 8]>
      <script>
          new jQueryCollapse($("#custom-show-hide-example"), {
              open: function() {
                  this.slideDown(150);
              },
              close: function() {
                  this.slideUp(150);
              }
          });
      </script>
<![endif]-->


<script>
    $(document).ready(function () {
        var submiturl = "";
        var usedefaulturl = true;

        $("#btnSubmit").click(function () {
            usedefaulturl = true;
        });
        $("#btnSave").click(function () {
            submiturl = '@(Url.Content("~/Archive/SaveChairReviewFeedback"))';
            usedefaulturl = false;
        });

        $("#dialog-message").hide();

        $("form").validate({
            submitHandler: function (form) {
                // alert("submitted!");
                form.submit();
            },
            invalidHandler: function (event, validator) {
                //alert("no score");

            }
        });

        $("form").submit(function (event) {
            event.preventDefault();
            // Show the "busy" Gif:
            if ($(this).valid()) {
                $('#msg_in_dialog').html("Processing...<br/><br/><img src='@Url.Content("~/images/ajax-loader.gif")'>");
                $("#dialog-message").dialog({
                    modal: true
                });

                var url = $(this).attr("action");
                if (!usedefaulturl)
                    url = submiturl;
                var formData = $(this).serialize();
                $.ajax({
                    url: url,
                    type: "POST",
                    data: formData,
                    dataType: "json",
                    success: function (url) {
                        // Hide the "busy" gif:
                        var res = url.split(";");
                        $('#msg_in_dialog').html("Changes saved.<br/>");
                        if (!usedefaulturl) {
                            $('#msg_in_dialog').html("Changes saved.<br/>However, you need to submit it to make it available for editor.");
                        }
                        $("#dialog-message").dialog({
                            modal: true,
                            buttons: {
                                "Continue": function () {
                                    $("body").css("cursor", "progress");
                                    window.location.href = url;
                                    $(this).dialog("close");
                                }
                            }
                        });
                        // Do something useful with the data:
                    }
                })
            }
            else {
                //$('#msg_in_dialog').html("Please complete all the fields.");
                //$("#dialog-message").dialog({
                //    modal: true,
                //    buttons: {
                //        "Close": function () {
                //            $(this).dialog("close");
                //        }
                //    }
                //});
            }
        });
    });
</script>
